<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
        $this->table = $this->db->dbprefix("user");
    }


    public function add_row($data=array())
    {
        if(is_array($data)){
            if($this->db->insert($this->table,$data)){
                return $this->db->insert_id();
            }else{
                return false;
            }
        }
    }


    /**
     * 获取单条记录
     * @param array $where 查询条件
     * @param string $field 显示字段
     * @return mixed
     */
    function get_row($where=array(),$field='*')
    {
        if(!empty($field))$this->db->select($field);
        $query = $this->db->get_where($this->table,$where,1);
        return $query->row_array();
    }

    /**
     * 更新数据
     * @param $data 数据数组
     * @param $where 更新条件
     * @param bool $nosid
     * @return mixed
     */
    function edit_row($data,$where)
    {
        $this->db->where($where, NULL, FALSE);
        return $this->db->update($this->table,$data);
    }
}